package com.lthlearn.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

/**
 * @author: 2942733239@qq.com
 * @date: 2024/11/4 10:03
 * @description: com.lthlearn.util
 * @version: 1.0
 */
@Component
public class EmailUtil {

    @Autowired
    private JavaMailSender mailSender;

    public void send(String loginEmail, String randomCode) {
        // 1.创建封装邮箱信息的对象
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        // 2.封装信息
        // 发送方
        simpleMailMessage.setFrom("2942733239@qq.com");
        simpleMailMessage.setSubject("StartTravel 验证码");
        // 验证码
        simpleMailMessage.setText(randomCode);
        // 接收方
        simpleMailMessage.setTo(loginEmail);
        // 3.发送验证码
        mailSender.send(simpleMailMessage);
    }

}
